﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Configuration;
using Contracts;
using System.Threading;

namespace RadarClient {
    class RadarClient {

        private static readonly string configFile = ConfigurationManager.AppSettings["clientConfigFile"];

        static void Main(string[] args) {
            RemotingConfiguration.Configure(configFile, false);
            WellKnownClientTypeEntry[] entries = RemotingConfiguration.GetRegisteredWellKnownClientTypes();
            IRadar _radar = (IRadar)Activator.GetObject(entries[0].ObjectType, entries[0].ObjectUrl);
            Timer t = new Timer(GetData, _radar, 10000, 10000);
            Console.WriteLine("Client started ...");
            Console.WriteLine("Press Enter to stop the client.");
            Console.ReadLine();
        }

        static void GetData(Object o) {
            List<IEvent> evts = ((IRadar)o).ReadEvents();
            Console.WriteLine("---------------");
            Console.WriteLine("Otained events:");
            evts.ForEach(e => Console.WriteLine(e));
            Console.WriteLine("---------------");
        }
    }
}
